<%--
 * Copyright (c) 2013 WDCY Information Technology Co. Ltd
 * www.wdcy.cc
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * WDCY Information Technology Co. Ltd ("Confidential Information").
 * You shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement you
 * entered into with WDCY Information Technology Co. Ltd.
--%>
<%--
 * 
 * @author Shengzhao Li
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="dis" uri="http://displaytag.sf.net" %>
<!DOCTYPE HTML>
<html>
<head>
    <title>Instances</title>
</head>
<body>
<%--Alert--%>
<div class="row">
    <div class="col-md-12">
        <div class="alert alert-success" style="display: none;">
            <button type="button" class="close" data-dismiss="alert">&times;</button>
            <div><em class="fui-check-circle"></em>
                <span id="saveInstanceOK" style="display: none;">Save instance successful</span>
                <span id="enableSuccess" style="display: none;">Enable instance heart-beat successful</span>
                <span id="stopSuccess" style="display: none;">Stop instance heart-beat successful</span>
                <span id="deleteSuccess" style="display: none;">Delete instance successful</span>
            </div>
        </div>
        <div class="alert alert-danger" style="display: none;">
            <button type="button" class="close" data-dismiss="alert">&times;</button>
            <div><em class="fui-check-circle"></em>
                <span id="enableFailed" style="display: none;">Fail to enable instance heart-beat monitoring; Please checking server-console what happening...</span>
                <span id="stopFailed" style="display: none;">Fail to stop instance heart-beat monitoring; Please checking server-console what happening...</span>
                <span id="deleteFailed"
                      style="display: none;">Delete instance failed; Make sure it is not-enabled</span>
            </div>
        </div>

    </div>
</div>
<div class="row">
    <div class="col-md-4">
        <form class="form-inline" role="form" action="" id="filterForm">
            <div class="input-group">
                <input type="text" name="instanceName" class="form-control" id="instanceName"
                       placeholder="Instance name" value="${listDto.instanceName}"/>
                <span class="input-group-btn">
                    <button type="submit" class="btn"><i class="fui-search"></i></button>
                </span>
            </div>
            <strong>${listDto.totalSize}</strong> instance(s)
        </form>
    </div>
    <div class="col-md-2">
        &nbsp;
    </div>
    <div class="col-md-4 col-md-offset-2">
        <div class="pull-right">
            <a href="instance_form.hb" class="btn btn-primary"><i class="fui-plus"></i> New Instance</a>
        </div>
    </div>
</div>
<div class="row">
    <div class="col-md-12">
        <dis:table list="${listDto}" id="d" form="filterForm" class="table table-striped table-hover">
            <dis:column title="Instance Name">
                <c:if test="${d.enabled}">
                    <em class="fui-time" title="Monitoring"></em>
                </c:if>
                ${d.instanceName}
            </dis:column>
            <dis:column title="URL">
                <a href="${d.monitorUrl}" target="_blank">${d.monitorUrl}</a>
            </dis:column>
            <dis:column title="Frequency(s)" property="frequency.seconds"/>
            <dis:column title="<abbr title='Max Connection Time(s)'>Max Conn(s)</abbr>"
                        property="maxConnectionSeconds"/>
            <dis:column title="Email">
                <a href="mailto:${d.email}">${d.email}</a>
            </dis:column>
            <dis:column title="Action">
                <c:if test="${not d.enabled}">
                    <a href="enable.hb?guid=${d.guid}" title="Monitoring"
                       onclick="return confirm('Enable heart-beat by instance[${d.instanceName}] now ?')"><em
                            class="fui-star"></em></a>
                    &nbsp;
                    <a href="instance_form.hb?guid=${d.guid}" title="Edit"><em class="fui-new"></em></a>
                    &nbsp;
                    <a href="delete.hb?guid=${d.guid}" title="Delete"
                       onclick="return confirm('Are you sure delete the instance[${d.instanceName}] (include heart-beat logs) ?')"><em
                            class="fui-cross"></em></a>
                </c:if>
                <c:if test="${d.enabled}">
                    <a href="${contextPath}/monitoring/${d.guid}.hb" title="Monitoring"><em class="fui-time"></em></a>
                    &nbsp;
                    <a href="stop.hb?guid=${d.guid}" title="Stop"
                       onclick="return confirm('Stop heart-beat by instance[${d.instanceName}] now ?')"><em
                            class="fui-pause"></em></a>
                </c:if>
            </dis:column>
        </dis:table>
    </div>
</div>
<script>
    $(function () {
        new InstanceList('${param.alert}');
    })
</script>
</body>
</html>